home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amoszine 5
/
Amoszine 5.adf
/
arts
/
Chapter29.asc.cm
/
Chapter29.asc.cm
Wrap
Text File
|
1992-02-26
|
5KB
|
223 lines
<>{The Absolute Beginners Guide To Amos@6
}Chapter Twenty Nine
@4
Imagine an enormous game like Populous
or Elite without a save game option!
They would be almost unplayable
without it.
I would now like to show you how to
set up a load and save game feature
for your own programs.
It's a fairly straight forward affair
doing this in Amos but it has NEVER
been covered anywhere, not in the Amos
manual, books or magazines that I have
seen. So how is a beginner meant to
know how to do this?
@6
Don't worry, read on....
@4
When you save a games position all you
have to do is save ALL of the
variables into a file. It's as simple
as that!
First, decide where you are going to
put your saved game feature, the main
menu would be the usual place. Set up
your menu with LOAD and SAVE in it
and when selected by the user call the
Procedures _Load and _Save
respectively.
We of course, need to write the _Load
and _Save procedures first.
Let's look at writing _Save first.
First of all we need to have a list of
EVERY variable used in the game, you
may not actually need to save all of
them, but if you are not sure about
any particular one then include it
anyway.
Once you have written down all of your
programs variables you are ready to
write the _Save game procedure.
To keep this example simple we will
not offer the user a file selector but
we will save the games position with a
predefined name. This means only one
game can ever be saved on a single
disk as any subsequent saves will
overwrite the last save. This keeps
things very simple and will hopefully
mean you will understand it a lot
easier.
Of course, once you have learnt the
basics of loading and saving variables
you can expand these procedures into
your own custom routines, specific to
your program.
I am going to make up an imaginary
game that has only four variables in
it. The variables are:
@1
POINTS
FRUITS (5)
MONSTER$(25)
FIRE$
@4
As we now know all of the variables of
our game we can PRINT them to a disk!
But first we must OPEN a channel. You
do not need to understand how this
works,just remember that when you OPEN
a channel it MUST be closed after you
have finished with it.
@1
Open Out 1,"DF0:SAVED_GAME"
@4
This OPENs a channel which we will
call 1 for our reference. You can have
more than one channel open at a time,
but I doubt you will ever find the
need to, so just use 1 all of the
time. The "DF0:SAVED_GAME" is the path
and file name we will be creating on
the disk. Remember the comma and the
quotes around the file name. You can
put in any path or call the file
anything you wish of course.
Now we can get to work on actually
saving the variables onto the disk.
@1
PRINT #1,POINTS
@4
This line will save the variable
POINTS and it's current value to the
file we have called SAVED_GAME.
The #1 tells Amos we are printing to
channel one.
Now we want to save the dimensioned
array FRUITS() which has five elements
- this too is fairly simple.
@1
For A=1 To 5
Print #1,FRUITS(A)
Next A
@4
We have used a For Next loop to put
the five elements onto disk which is
stored along with POINTS in the file
"SAVED_GAME"
Next we have MONSTER$() a 25 element
string array. This is virtually the
same.
@1
For A=1 To 25
Print #1,MONSTER$(A)
Next A
@4
And lastly, we have a nice simple
string variable.
@1
PRINT #1,FIRE$
@4
Don't forget to CLOSE channel 1,
@1
CLOSE 1
@4
And that's it, all the four variables
and their values are all stored neatly
into one file on disk ready to restore
the game to it's original position.
So, lumping it all together, here is
the Procedure in full.
@1
Procedure _SAVE
Open Out 1,"DF0:SAVED_GAME"
PRINT #1,POINTS
For A=1 To 5
Print #1,FRUITS(A)
Next A
For A=1 To 25
Print #1,MONSTER$(A)
Next A
PRINT #1,FIRE$
CLOSE 1
End Proc
@4
Obviously to make use of this
procedure in your own programs you
will need to enter the variables
pertaining to your own particular
program.
Now we must look at how to load back
the variables into your program.
Luckily it's all very simple if you
understood how the save part works.
All we need to do is substitute the
PRINT statements for INPUT statements.
So all we have to do is cut and paste
the _save procedure, rename it _LOAD
and change the PRINTs to INPUTs.
@1
Procedure _LOAD
Open In 1,"df0:SAVED_GAME"
Input #1,POINTS
For A=1 To 5
Input #1,FRUITS(A)
Next A
For A=1 To 25
Input #1,MONSTER$(A)
Next A
Input #1,FIRE$
CLOSE 1
End Proc
@4
See example29.Amos for a small
demonstration.
@6
End of Chapter Twenty Nine
^^^^^^^^^^^^^^^^^^^^^^^^^^^